<?php

if(GetParam("form","")=="Bank"){$type = "BAYAR BANK";$dk = "D";}
if(GetParam("form","")=="Cash"){$type = "BAYAR KAS";$dk = "D";}

$res_query  = $DBConnection->dbc->get_results("SELECT *, DATE_FORMAT(tglbkt,'%d/%m/%y') as tanggal FROM ais_memorial WHERE nobkt = '".GetParam("nobkt","")."' AND dk = '$dk'",ARRAY_N);
$res_query2 = $DBConnection->dbc->get_row("SELECT *, DATE_FORMAT(tglbkt,'%d/%m/%y') as tanggal FROM ais_memorial WHERE nobkt = '".GetParam("nobkt","")."' AND dk <> '$dk'");

/*
    $queryq = mysql_db_query($db_name,"SELECT *, DATE_FORMAT(tglbkt,'%d/%m/%y') as tanggal FROM ais_memorial WHERE nobkt = '$nobukti' AND dk = '$dk'");
    $query = mysql_fetch_row($queryq);

    $query2q = mysql_db_query($db_name,"SELECT *, DATE_FORMAT(tglbkt,'%d/%m/%y') as tanggal FROM ais_memorial WHERE nobkt = '$nobukti' AND dk <> '$dk'");
    $query2 = mysql_fetch_row($query2q);

    $valutaq = mysql_db_query($db_name,"SELECT * FROM tblcurrency WHERE tucode = '$query[21]'");
    $valuta = mysql_fetch_row($valutaq);
*/

class PDFReport extends FPDF
{
//Page header
function Header()
{

    global $nobukti,$type,$res_query2,$valuta,$DEFINE_FONT;
    // Kop Surat / Judul...

	if ($DEFINE_FONT==0) {
		$this->AddFont('arialn','','arialn.php');
		$DEFINE_FONT=1;
	}

    $this->SetFont('arialn','',8);
    $this->Cell(45,3,'PT. MASAJI TATANAN CONTAINER',0,1,'C');
    $this->SetFont('arialn','',8);
    $this->Cell(45,3,'Jl. Yos Sudarso No. 1 Block B/15',0,1,'C');
    $this->Cell(45,3,'Tanjung Priok',0,0,'C');
    $this->SetFont('arialn','',16);
    $this->Cell(90,9,$type,0,0,'C');
    $this->SetFont('arialn','',6);
    $this->Cell(45,9,'',0,1,'C');

    $this->SetFont('arialn','',7);
    $this->Cell(55,5,'Diterima Untuk :',0,0,'R');
    $this->Cell(105,5,'No. Bukti :',0,0,'R');
    $this->Cell(20,5,GetParam("nobkt",""),0,1,'L');

    $this->Cell(55,5,'Diterima Dari :',0,0,'R');
    $this->Cell(55,5,$res_query2->debtur.', '.$res_query2->debnam,0,0,'L');
    $this->Cell(50,5,'Tanggal :',0,0,'R');
    $this->Cell(20,5,$res_query2->tanggal,0,1,'L');

    $this->Cell(160,5,'Valuta :',0,0,'R');
    $this->Cell(20,5,$res_query2->curr,0,1,'L');


    // Mulai header table...
    $this->SetFont('arialn','',6);
    $this->Cell(10,5,'NO.',1,0,'C');
    $this->Cell(55,5,'URAIAN',1,0,'C');
    $this->Cell(25,5,'KODE',1,0,'C');
    $this->Cell(40,5,'JUMLAH',1,0,'C');
    $this->Cell(10,5,'DK',1,0,'C');
    $this->Cell(10,5,'KTR',1,0,'C');
    $this->Cell(10,5,'UU',1,0,'C');
    $this->Cell(20,5,'REFERENSI',1,1,'C');

}

// Main looping...
function MainLoop()
{

    global $res_query;

    $this->SetFont('arialn','',6);
    $this->Cell(10,3,'','L',0,'C');
    $this->Cell(55,3,'','L',0,'C');
    $this->Cell(25,3,'','L',0,'C');
    $this->Cell(40,3,'','L',0,'C');
    $this->Cell(10,3,'','L',0,'C');
    $this->Cell(10,3,'','L',0,'C');
    $this->Cell(10,3,'','L',0,'C');
    $this->Cell(20,3,'','LR',1,'C');

    if ($res_query) {
   	 foreach ($res_query as $query) {

	    $no++;

	    // Table yang akan di looping...
	    $this->SetFont('arialn','',6);
	    $this->Cell(10,3,$no,'L',0,'C');
	    $this->Cell(55,3,$query[16],'L',0,'L');
	    $this->Cell(25,3,$query[11],'L',0,'C');
	    $this->Cell(40,3,number_format($query[22],2),'L',0,'R');
	    $this->Cell(10,3,$query[23],'L',0,'C');
	    $this->Cell(10,3,$query[4],'L',0,'C');
	    $this->Cell(10,3,$query[15],'L',0,'C');
	    $this->Cell(20,3,$query[9],'LR',1,'C');

	 }
    }

    $this->SetFont('arialn','',6);
    $this->Cell(10,9,'','L',0,'C');
    $this->Cell(55,9,'','L',0,'C');
    $this->Cell(25,9,'','L',0,'C');
    $this->Cell(40,9,'','L',0,'C');
    $this->Cell(10,9,'','L',0,'C');
    $this->Cell(10,9,'','L',0,'C');
    $this->Cell(10,9,'','L',0,'C');
    $this->Cell(20,9,'','LR',1,'C');

}

//Page footer
function Footer()
{

    global $res_query2;
    
    // Table pada akhir / footer...
    $this->SetFont('arialn','',6);
    $this->Cell(10,5,'','LRT',0,'C');
    $this->Cell(55,5,'Terbilang :','LRT',0,'L');
    $this->Cell(25,5,$res_query2->skada,'LRBT',0,'C');
    $this->Cell(40,5,number_format($res_query2->jumlah,2),'LRBT',0,'R');
    $this->Cell(10,5,$res_query2->dk,'LRBT',0,'C');
    $this->Cell(10,5,$res_query2->ktrasl,'LRBT',0,'C');
    $this->Cell(10,5,$res_query2->untush,'LRBT',0,'C');
    $this->Cell(20,5,$res_query2->noref,'LRBT',1,'C');
    $this->Cell(10,5,'','LR',0,'C');
    $this->Cell(55,5,'','LRB',0,'L');
    $this->Cell(115,5,'','R',1,'L');

    $this->Cell(180,5,'','LR',1,'L');

    $this->Cell(15,5,'Debitur/Princ.','L',0,'L');
    $this->Cell(75,5,':   '.$res_query2->princ,'B',0,'L');
    $this->Cell(10,5,'   Port',0,0,'L');
    $this->Cell(10,5,':',0,0,'R');
    $this->Cell(50,5,$res_query2->port,'B',0,'L');
    $this->Cell(20,5,'','R',1,'L');

    $this->Cell(15,5,'Vessel','L','L',0);
    $this->Cell(75,5,':   '.$res_query2->vessel,'B',0,'L');
    $this->Cell(90,5,'','R',1,'L');

    $this->Cell(15,5,'Voyage','L','L',0);
    $this->Cell(75,5,':   '.$res_query2->voyage,'B',0,'L');
    $this->Cell(10,5,'   T.A.',0,0,'L');
    $this->Cell(10,5,'o',0,0,'C');
    $this->Cell(10,5,'o',0,0,'C');
    $this->Cell(20,5,'',0,0,'C');
    $this->Cell(10,5,'From',0,0,'L');
    $this->Cell(10,5,':',0,0,'L');
    $this->Cell(20,5,$res_query2->arrdat,'RB',1,'L');

    $this->Cell(15,5,'Job/No. Order','L',0,'L');
    $this->Cell(75,5,':   '.$res_query2->noorder,'B',0,'L');
    $this->Cell(10,5,'   T.D.',0,0,'L');
    $this->Cell(10,5,'o',0,0,'C');
    $this->Cell(10,5,'o',0,0,'C');
    $this->Cell(20,5,'',0,0,'C');
    $this->Cell(10,5,'To.',0,0,'L');
    $this->Cell(10,5,':',0,0,'L');
    $this->Cell(20,5,$res_query2->arrdat,'RB',1,'L');

    $this->Cell(180,5,'','RBL',1,'L');

    // Tabel tanda tangan...
    $this->SetFont('arialn','',6);
    $this->Cell(60,5,'SETUJU TERIMA',1,0,'C');
    $this->Cell(60,5,'PENYETOR',1,0,'C');
    $this->Cell(60,5,'PENERIMA',1,1,'C');


    $this->Cell(15,5,'NAMA',1,0,'C');
    $this->Cell(45,5,'',1,0,'C');
    $this->Cell(15,5,'NAMA',1,0,'C');
    $this->Cell(45,5,'',1,0,'C');
    $this->Cell(15,5,'NAMA',1,0,'C');
    $this->Cell(45,5,'',1,1,'C');

    $this->Cell(15,15,'TTD',1,0,'C');
    $this->Cell(45,15,'',1,0,'C');
    $this->Cell(15,15,'TTD',1,0,'C');
    $this->Cell(45,15,'',1,0,'C');
    $this->Cell(15,15,'TTD',1,0,'C');
    $this->Cell(45,15,'',1,1,'C');



    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('arialn','',8);
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}


//Instanciation of inherited class
$pdf=new PDFReport("P","mm","letter");
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('arialn','',12);
//for($i=1;$i<=40;$i++){
//    $pdf->Cell(0,10,'Query ke: '.$i,"B",1);
//}
$pdf->MainLoop();
$pdf->Output();

?>